import { Item } from 'ant-design-vue/lib/menu';
import Mock from 'mockjs'
import { param2Obj } from '../../utils/decompose'
interface MockList {
    id: string,
    key: string;
    name: number,
    block: number,
    type: string,
    Vipname: string,
    grade: any,
    number: string,
    consume: string,
    balance: string,
    save: string,
    score: string,
    Vipstate:any,
    begin: any,
    over: string,
}
let List: MockList[] = []
for (let i = 0; i < 400; i++) {
    let id = Mock.mock('@guid')
    List.push({
        id: id,
        key: id,
        name: Mock.mock('@id()'),
        block: Mock.mock(/\d{5,10}/),
        type: Mock.mock('@integer(0, 2)'),
        Vipname: Mock.mock('@cname'),
        grade: 'Vip' + Mock.mock('@integer(0, 10)'),
        number: Mock.mock(/^1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1589]))\d{8}$/),
        consume: Mock.mock('@integer(1000, 20000)'),
        balance: Mock.mock('@integer(1000, 200200)'),
        save: Mock.mock('@integer(1000, 220000)'),
        score: Mock.mock('@integer(1000, 2000)'),
        Vipstate: Mock.mock('@integer(0, 1)'),
        begin: Mock.mock('@date("yyyy-MM-dd")'),
        over: Mock.mock('@date("yyyy-MM-dd")'),
    })
}
export default {
    MockList: (config: any) => {
        let { number,begin,Vipname, page, pagesize } = param2Obj(config.url)
        const newList = List.filter(item => {
          return item.Vipname.indexOf(Vipname) != -1
        })
        const newList1 = newList.filter((item:any) => {
            return  item.begin.indexOf(begin) != -1
          })
        const newList2 = newList1.filter((item, index) => {
            return (page - 1) * pagesize <= index && index < page * pagesize
        })
        return {
            code: 200,
            msg: "数据成功了",
            data: newList2,
            total: List.length
        }
    },
    MockListDel: (config: any) => {
        const { id } = JSON.parse(config.body)
        const index = List.findIndex(Item => {
            return Item.id !== id
        })
        List.splice(index, 1)
        return {
            code: 200,
            msg: "成功删除了",
            data: null,
        }
    },
    MockListDelAll: (config: any) => {
        const {ids} = JSON.parse(config.body)
        console.log('ids',ids);
         const newList2 = List.filter(item=>{
             return !ids.includes(item.id)  //filter是js语法中的数组方法(过滤器) 将满足条件的值放在一个新的数组,返回新数组
         })
         List = newList2
        return {
            code: 200,
            msg: "成功批量删除了",
            data: null,
        }
    },
    MockListAdd: (config: any) => {
        const {  type,  grade,Vipname,number,consume, balance, save, score, begin,over, } = JSON.parse(config.body)
        let id = Mock.mock('@guid')
        List.unshift({
            id:id,
            key:id,
            name:Mock.mock('@id()'),
            block: Mock.mock(/\d{5,10}/),
            type:type,
            grade:grade,
            Vipname:Vipname,
            number:number,
            consume:consume,
            balance:balance,
            save:save,
            score:score,
            Vipstate: Mock.mock('@integer(0, 1)'),
            begin:begin,
            over:over,
        })
        return {
            code: 200,
            msg: "添加成功",
            data: null,
        }
    }
}